package com.youchuang.action.indent;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.collections.CollectionUtils;
import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import com.youchuang.action.BaseAction;
import com.youchuang.action.cart.CartItem;
import com.youchuang.common.Constant;
import com.youchuang.service.CartService;

import net.sf.json.JSONArray;

/**
 * 订单确认页面
 * 
 * @author Administrator
 *
 */
@Namespace(value = "/indent")
@ParentPackage("shopping-default")
public class IndentConfirmAction extends BaseAction {
	private Logger logger = Logger.getLogger(IndentConfirmAction.class.getSimpleName());
	private List<CartItem> items;
	@Resource
	private CartService cartService;

	@Action(value = "confirm", interceptorRefs = { @InterceptorRef(value = "loginStack") }, results = {
			@Result(name = Constant.SUCCESS, location = "/WEB-INF/jsp/indent/indent_info.jsp"),
			@Result(name = Constant.EMPTY, type = "redirectAction", params = { "namespace", "/cart", "actionName",
					"viewAction" }) })
	public String execute() throws Exception {
		logger.info("execetion is execute");

		items = cartService.getItems(false);

		if (CollectionUtils.isEmpty(items)) {
			return Constant.EMPTY;
		}
		logger.info("response json = " + JSONArray.fromObject(items).toString());
		return Constant.SUCCESS;
	}

	public double getTotalDang() throws Exception {
		logger.info("execetion is getTotalDang");
		return cartService.total(false);
	}

	public List<CartItem> getItems() {
		return items;
	}

	public void setItems(List<CartItem> items) {
		this.items = items;
	}

}
